package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.ICountryDao;
import com.hy.erp.inventory.pojo.Country;
import com.hy.erp.inventory.pojo.interfaces.ICountry;
import com.hy.erp.inventory.service.interfaces.ICountryService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:17:44</li>
 * <li>类型名称：CountryService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@ Name ( "countryService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class CountryService extends AbstractBusinessService < ICountry > implements ICountryService
{

	@ Override
	public boolean addCountry (
								ICountry country )
	{





		if ( null == country)
		{
			return true ;
		}
		
		else
		{
			System.out
						.println ("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh") ;


			ICountryDao countryDao =
			                       ( ICountryDao ) this
			                                          .getDao ( ICountry.class ) ;
			
			return countryDao
			                .persist ( country ) ;
		}
		
	
	
	
	
	
	}

	@ Override
	public boolean modifyCountry (
									ICountry country )
	{





		if ( ( null == country )
			     || ( null == country
			                                .getIdentifier ( ) )
			     || ( country
			                        .getIdentifier ( )
			                        .trim ( )
			                        .length ( ) == 0 ) )
			{
				return true ;
			}
			else
			{

				ICountryDao countryDao =
                    ( ICountryDao ) this
                                       .getDao ( ICountry.class ) ;

		
					
				if ( null == country )
				{
					throw new ArchitectureFoundationException  (
					                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
				}
				
				
				return (countryDao
				                  .merge ( country ) != null ) ;
			}
		
	
	
	
	
	
	}

	@ Override
	public Integer removeCountry (
									String [ ] countryIds )
	{





		if ( ( null == countryIds)
			     || ( countryIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{


				ICountryDao countryDao =
                    ( ICountryDao ) this
                                       .getDao ( ICountry.class ) ;
		

				return countryDao
				                .remove ( countryIds ) ;
			}
	
	
	
	
	
	}

	@ Override
	public String [ ] addCountry (
									Object [ ] country )
	{






		if ( null == country)
		{
			return null ;
		}
		
		else
		{
		

			ICountryDao countryDao =
			                       ( ICountryDao ) this
			                                          .getDao ( ICountry.class ) ;

			Country[] countrys=new Country[country.length];
						for(int i=0;i<country.length;i++)
						{
							Country country2=( Country ) country[i];
							countrys[i]=country2;
						}
						return countryDao
						                .persist ( countrys ) ;
			
		}
		
	
	
	
	
	
	
	}

	@ Override
	public List < ICountry > getAllCountry ( )
	{
		ICountryDao countryDao =
            ( ICountryDao ) this
                               .getDao ( ICountry.class ) ;


		return countryDao
		                .find ( );
	}

	@ Override
	public String [ ] modifyCountry (
										Object [ ] country )
	{







		if ( null == country)
		{
			return null ;
		}
		
		else
		{
		

			ICountryDao countryDao =
			                       ( ICountryDao ) this
			                                          .getDao ( ICountry.class ) ;

			Country[] countrys=new Country[country.length];
						for(int i=0;i<country.length;i++)
						{
							Country country2=( Country ) country[i];
							countrys[i]=country2;
						}
						return countryDao
						                .merge   ( countrys ) ;
			
		}
		
	
	
	
	
	
	
	
	}

}
